home *** CD-ROM | disk | FTP | other *** search
- *** /tmp/,RCSt1a00896 Wed Nov 28 09:31:16 1990
- --- PatchLevel.h Wed Nov 28 09:30:44 1990
- ***************
- *** 1,5 ****
- /*
- ! * PathLevel: 1
- *
- * the Patch Level above is to identify the version
- * of the all the files in this directory. given the above
- --- 1,5 ----
- /*
- ! * PathLevel: 2
- *
- * the Patch Level above is to identify the version
- * of the all the files in this directory. given the above
- *** /tmp/,RCSt1a00896 Wed Nov 28 09:31:18 1990
- --- phil.c Wed Nov 28 09:30:45 1990
- ***************
- *** 44,66 ****
- {"phil-4", (char *)NULL, 0x010, 4, 3, 0, 64, 0L, 0L, 0L, 0L, 0 }
- };
-
- ! /* forks: number of forks available to philosopher i
- * note: mutex access at all times (ie only one process may read/write
- ! * any element of forks at one time, implemented via semaphore).
- * usage:
- ! * at any time forks[i] can only be 0, 1, or 2
- ! * when a philosopher [i] wants to eat, forks[i] must be 2,
- * if it is
- ! * decrement forks to the right and left by one and start eating
- * otherwise
- ! * wait for event phil[i].event (ready condition for phil i) to occur.
- *
- ! * when a philosopher is done eating,
- ! * increments forks to left and right
- ! * if forks[left] == 2 cause event phil[left].event
- ! * if forks[right] == 2 cause event phil[right].event
- */
- ! int forks [] = { 2, 2, 2, 2, 2 };
-
- /* fork semaphore (queue) */
- char *forkSemaphore;
- --- 44,65 ----
- {"phil-4", (char *)NULL, 0x010, 4, 3, 0, 64, 0L, 0L, 0L, 0L, 0 }
- };
-
- ! /* forks: number of forks (according to the number of philosophers
- * note: mutex access at all times (ie only one process may read/write
- ! * one fork at one time, implemented via semaphore).
- * usage:
- ! * at any time forks[i] can only be 0 or 1
- ! * when a philosopher [i] wants to eat, forks[i] and forks[(i+1)%5]
- ! * must be 1
- * if it is
- ! * decrement this two forks by one and start eating
- * otherwise
- ! * wait for event phil[i].event (ready condition for phil i) to occur
- ! * and check again
- *
- ! * when a philosopher has done eating he puts back his two forks
- */
- ! int forks [] = { 1, 1, 1, 1, 1 };
-
- /* fork semaphore (queue) */
- char *forkSemaphore;
- ***************
- *** 87,102 ****
- PHIL *phil; /* philosopher requesting forks */
- {
- Pfork(phil->message); /* mutually exclusive access to forks */
- ! if(forks[phil->me] != 2)
- ! {
- Vfork(phil->message); /* release */
- phil->eventbuf = phil->event;
- e_wait(&phil->eventbuf, 0, 0L); /* wait for ready condition */
- Pfork(phil->message);
- ! }
- /* get the two forks */
- ! forks[phil->left]--;
- ! forks[phil->right]--;
- Vfork(phil->message);
- }
-
- --- 86,108 ----
- PHIL *phil; /* philosopher requesting forks */
- {
- Pfork(phil->message); /* mutually exclusive access to forks */
- ! while (1)
- ! {
- ! if(forks[phil->me] == 0 || forks[phil->right] == 0)
- ! {
- Vfork(phil->message); /* release */
- phil->eventbuf = phil->event;
- e_wait(&phil->eventbuf, 0, 0L); /* wait for ready condition */
- Pfork(phil->message);
- ! }
- ! else
- ! {
- ! break;
- ! }
- ! }
- /* get the two forks */
- ! forks[phil->me]=0;
- ! forks[phil->right]=0;
- Vfork(phil->message);
- }
-
- ***************
- *** 111,121 ****
- Pfork(phil->message);
-
- /* drop forks and signal any events */
- if(++forks[phil->left] == 2)
- e_signal(phils[phil->left].pid, phils[phil->left].event);
- if(++forks[phil->right] == 2)
- e_signal(phils[phil->right].pid, phils[phil->right].event);
- !
- Vfork(phil->message);
- }
-
- --- 117,132 ----
- Pfork(phil->message);
-
- /* drop forks and signal any events */
- + forks[phil->me] = 1;
- + forks[phil->right] = 1;
- + e_signal(phils[phil->left].pid, phils[phil->left].event);
- + e_signal(phils[phil->right].pid, phils[phil->right].event);
- + /*
- if(++forks[phil->left] == 2)
- e_signal(phils[phil->left].pid, phils[phil->left].event);
- if(++forks[phil->right] == 2)
- e_signal(phils[phil->right].pid, phils[phil->right].event);
- ! */
- Vfork(phil->message);
- }
-
- ***************
- *** 142,151 ****
- moveto(4, phil->col); printf(" Eating "); fflush(stdout);
- Vscreen(phil->message);
- p_pause( (long)(((Rand() & 15) + 1) * 1000L) );
- - putdown(phil);
- Pscreen(phil->message);
- moveto(4, phil->col); printf(" Thinking "); fflush(stdout);
- Vscreen(phil->message);
- p_pause( (long)(((Rand() & 15) + 1) * 1000L) );
- }
- /*NOTREACHED*/
- --- 153,162 ----
- moveto(4, phil->col); printf(" Eating "); fflush(stdout);
- Vscreen(phil->message);
- p_pause( (long)(((Rand() & 15) + 1) * 1000L) );
- Pscreen(phil->message);
- moveto(4, phil->col); printf(" Thinking "); fflush(stdout);
- Vscreen(phil->message);
- + putdown(phil);
- p_pause( (long)(((Rand() & 15) + 1) * 1000L) );
- }
- /*NOTREACHED*/
-